import request from "@/utils/request";
import type {
  GetAttrListParams,
  AttrList,
  AttrItem,
} from "./models/attrModels";

enum Api {
  getAttrListUrl = `/admin/product/attrInfoList`,
  addOrUpdateAttrUrl = `/admin/product/saveAttrInfo`,
  delAttrUrl = `/admin/product/deleteAttr`,
}

/**
 * 获取属性列表
 * @param GetAttrListParams
 * @returns AttrList
 */
export const getAttrListApi = ({
  category1Id,
  category2Id,
  category3Id,
}: GetAttrListParams) => {
  return request.get<any, AttrList>(
    Api.getAttrListUrl + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 添加或更新属性
 * @param attr 属性
 * @returns null
 */
export const addOrUpdateAttrApi = (attr: AttrItem) => {
  return request.post<any, null>(Api.addOrUpdateAttrUrl, attr);
};

/**
 * 删除属性
 * @param attrId 属性id
 * @returns null
 */
export const delAttrApi = (attrId: number) => {
  return request.delete<any, null>(Api.delAttrUrl + `/${attrId}`);
};
